class Solution {
public:
    bool canJump(vector<int>& nums)
    {
        int left = 0, right = 0, n = nums.size(), maxpos = 0;
        while (right >= left)
        {
            if (maxpos >= n - 1)
            {
                return true;
            }

            for (int i = left; i <= right; i++)
            {
                maxpos = max(maxpos, nums[i] + i);
            }
            left = right + 1;
            right = maxpos;
        }
        return false;
    }
};